<?php
include('config.php');
session_start();

if ($_SESSION['access_level'] >= 4) {

	if (!session_is_registered("myusername")) {
		echo "Please log out and back in";
	}

	$data = NULL;
	
	echo "<table width=\"100%\">";
	echo "<tr><th width=\"100px\">Serial Number</th><th width=\"75px\">Model</th><th>Description</th><th width=\"100px\">Submitted BY</th><th width=\"125px\">Submitted On</th><th width=\"75px\">Device Sent</th></tr>";
		$faulty_results = mysql_query("SELECT * FROM faulty_modem WHERE device_sent = '0'");

	for ($i = '0'; $row = mysql_fetch_array($faulty_results), $i <= mysql_num_rows($faulty_results); $i++)
        	{
                	//changes the background color of the row based on if the row is even or odd
                	$row_bg_color=($i % 2 == 0) ? "#e5e5e5" : "#ffffff";
		
			echo "<tr onMouseOver=\"this.style.background= '#ffff99'\" onMouseOut=\"this.style.background= '$row_bg_color'\" style=\"background: $row_bg_color; border-top: solid 1px #000000\">";
			echo "<td>" . $row['serial'] . "</td>";
			echo "<td>" . $row['model'] . "</td>";
			echo "<td>" . $row['problem_description'] . "</td>";
			echo "<td>" . $row['submitted_by'] . "</td>";
			echo "<td>" . $row['submitted_on'] . "</td>";
			echo "<td>" . $row['device_sent'] . "</td>";
			echo "</tr>";

			//This contains the data that will be printed
			$data .= $row['serial'] . ",";
			$data .= $row['model'] . ",";
			$data .= $row['problem_description'] . "<br/>";

		}
	echo "</table>";
	echo "<input type='button' value='Print' onClick='printList(\"$data\")' />";
}
?>

<script type="text/javascript">

function printList(data) {
	alert(data);
	top.wRef = window.open('','myconsole','width=500,height=450,left=10,top=10'
		+',menubar=1'
		+',toolbar=0'
		+',status=1'
		+',scrollbars=1'
		+',resizable=1');

	top.wRef.document.writeln(data);
	top.wRef.print();
	top.wRef.close();

}

</script>

